import Mat4 from "./Mat4";

export default class Trs {

    static toMat4(out: Mat4, trs: number[]) {
        let mat = out.matrix;
        let x = trs[3], y = trs[4], z = trs[5], w = trs[6];
        let sx = trs[7], sy = trs[8], sz = trs[9];
        let xx = x * x;
        let xy = x * y;
        let xz = x * z;
        let yy = y * y;
        let yz = y * z;
        let zz = z * z;
        let wx = w * x;
        let wy = w * y;
        let wz = w * z;
        mat[0] = (1 - 2 * (yy + zz)) * sx;
        mat[1] = (2 * (xy - wz)) * sx;
        mat[2] = (2 * (xz + wy)) * sx;
        mat[3] = 0;
        mat[4] = (2 * (xy + wz)) * sy;
        mat[5] = (1 - 2 * (xx + zz)) * sy;
        mat[6] = (2 * (yz - wx)) * sy;
        mat[7] = 0;
        mat[8] = (2 * (xz - wy)) * sz;
        mat[9] = (2 * (yz + wx)) * sz;
        mat[10] = (1 - 2 * (xx + yy)) * sz;
        mat[11] = 0;


        mat[12] = trs[0];
        mat[13] = trs[1];
        mat[14] = trs[2];
        mat[15] = 1;

        return out;
    }
}